<template>
  <div>
    <el-button :id="id" type="text" @click="handleOpen">{{data.supplierName}}</el-button>
    <SupplierInfoDialog ref="dialog" />
  </div>
</template>

<script>
import SupplierInfoDialog from '@/components/SupplierInfoDialog'
import { getSupplierInfoByCode } from '@/api/supplier'
import { setSession } from '@/utils/util'

export default {
  name: 'SupplierLink',
  components: { SupplierInfoDialog },
  props: {
    id: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      data: {}
    }
  },
  watch: {
    id(n, o) {
      this.getData()
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      this.data = {}
      if (this.id) {
        getSupplierInfoByCode(this.id).then(res => {
          if (res.data) {
            this.data = res.data.supplierInfo
          }
        })
      }
    },
    handleOpen(){
      // const from = { record: this.data, from: 'supplier' }
      setSession('record', this.data)
      this.$refs.dialog.open()
    }
  }
}
</script>